from game import zz_game
from zz import zz_log, zz_img

log = zz_log.of()


# 寻道大千

class Game(zz_game.ZZ_Game):
    def __init__(self, d, has_prize=True):
        super().__init__(d, has_prize)

    def get_name(self):
        return "叫我大掌柜"

    def handle_main(self):
        self.log_msg("等待进入游戏页面")
        self.img_exit("./game/img/叫我大掌柜/alert.png", 20)
        self.alert_close("./game/img/叫我大掌柜/alert.png")
        self.log_msg("进去游戏")
        self.img_click("./game/img/叫我大掌柜/go.png")
        self.log_msg("等待进入游戏")
        self.img_exit("./game/img/叫我大掌柜/play.png", 20)
        self.log_msg("已进入游戏")
        self.log_msg("检查是否存在弹窗")
        while True:
            if self.alert_close("./game/img/叫我大掌柜/alert.png"):
                continue
            break

        if self.not_prize_handle():
            return False

        self.log_msg("开始锤打")
        while not self.check_done():
            for i in range(5):
                self.log_msg(f"锤第{i + 1}下")
                self.d.sleep(2)
                self.img_click("./game/img/叫我大掌柜/play.png")
                if self.img_exit("./game/img/叫我大掌柜/play_3.png", 3):
                    self.log_msg(f"锤力上升")
                    self.img_click("./game/img/叫我大掌柜/play_1.png")
                else:
                    self.log_msg(f"锤力下降")
                    self.img_click("./game/img/叫我大掌柜/play_0.png")

        return True
